﻿@using Model;
@{
    ViewBag.Title = "编辑博客";
    ViewBag.BlogCss = "active";
    List<Tag> taglist = ViewBag.TagList;
    List<Category> catelist = ViewBag.CateList;
    Blog m = ViewBag.model;
}
<ul class="breadcrumb">
    <li>博客管理<span class="divider">/</span></li>
    <li class="active">@ViewBag.Title</li>
</ul>
<div class="container-fluid">
    <div class="row-fluid">

        <div class="row-fluid">

            <div class="btn-toolbar">
                <button class="btn btn-primary" onclick="blogsave(0)"><i class="fa fa-save"></i> 保存为草稿</button>
                <button class="btn btn-primary" onclick="blogsave(1)"><i class="fa fa-save"></i> 保存并发表</button>
                <div class="btn-group">
                </div>
            </div>
            <div>
                <input id="blogid" name="blogid" type="hidden" value="@m.blog_id" />
                <label>博客标题</label>
                <input type="text" id="title" name="title" style="width:500px;" value="@m.blog_title">
                <label>博客分类</label>
                <div class="form-control" style="margin-bottom:9px;">
                    @foreach (var item in catelist)
                    {
                        if (m.blog_cate.IndexOf("【" + item.cate_id + "】") > -1)
                        {
                            <input type="checkbox" name="blogcate" checked="checked" value="@item.cate_id">@item.cate_name
                        }
                        else
                        {
                            <input type="checkbox" name="blogcate" value="@item.cate_id">@item.cate_name
                        }
                    }

                    </div>
                    <label>博客标签</label>
                    <div class="form-control" style="margin-bottom:9px;">
                        @foreach (var item in taglist)
                        {
                            if (m.blog_tags.IndexOf("【" + item.tag_id + "】") > -1)
                            {
                                <input type="checkbox" name="blogtag" checked="checked" value="@item.tag_id">@item.tag_name
                            }
                            else
                            {
                                <input type="checkbox" name="blogtag" value="@item.tag_id">@item.tag_name
                            }

                        }
                    </div>
                    <label>博客副标题</label>
                    <script id="subtitle" type="text/plain" style="width:800px;height:170px; margin-bottom:9px;">
                        @Html.Raw(m.blog_subtitle)
                    </script>
                    <label>博客内容</label>
                    <script id="content" type="text/plain" style="width:800px;height:300px;margin-bottom:9px;">
                        @Html.Raw(m.blog_content)
                    </script>
                </div>
            </div>

                @Html.Partial("_footer")

            </div>
        </div>

        <link href="/Content/js/plugins/ueditor1_4_3/themes/default/css/ueditor.min.css" rel="stylesheet" />
        <script type="text/javascript" charset="utf-8" src="/Content/js/plugins/ueditor1_4_3/ueditor.config.js"></script>
        <script type="text/javascript" charset="utf-8" src="/Content/js/plugins/ueditor1_4_3/ueditor.all.min.js"> </script>
        <script type="text/javascript" charset="utf-8" src="/Content/js/plugins/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>

        <script>
            var editor = new UE.ui.Editor({
                toolbars: [['source', '|', 'simpleupload']],
                maximumWords: 300
            });
            editor.render("subtitle");
            editor.ready(function () {
                editor.execCommand('serverparam', {
                    'uploadtype': 'blog'
                });
            });

            var content = UE.getEditor('content');
            content.ready(function () {
                content.execCommand('serverparam', {
                    'uploadtype': 'blog'
                });
            });
            //保存
            function blogsave(type) {
                //标签
                var tags = document.getElementsByName("blogtag");
                var tag = "";
                for (t in tags) {
                    if (tags[t].checked)
                        tag += '【' + tags[t].value + '】';
                }
                //分类
                var cates = document.getElementsByName("blogcate");
                var cate = "";
                for (c in cates) {
                    if (cates[c].checked)
                        cate += '【' + cates[c].value + '】';
                }
                var title = $("#title").val();
                if (title == "") {
                    AlertDialog("标题不能为空！");
                    return;
                }
                if (tag == "") {
                    AlertDialog("请选择标签！");
                    return;
                }
                if (cate == "") {
                    AlertDialog("请选择分类!");
                    return;
                }

                var data = [{ 'name': 'blogid', 'value': $("#blogid").val() },
                    { 'name': 'title', 'value': title },
            { 'name': 'cate', 'value': cate },
            { 'name': 'tag', 'value': tag },
            { 'name': 'type', 'value': type },
            { 'name': 'subtitle', 'value': editor.getContent() },
            { 'name': 'content', 'value': content.getContent() },
                ];
                AjaxPost('/Admin/Blog/Save', data, function (mess) {
                    AlertDialog(mess.msg);
                });
            }
        </script>
